clear all;
q = 10^(40/10);
T = 1e-3;
fi = 10e6;
fd = 50e6;
Tpn = (1e-3)/5110;
Td = 1/fd;
A = sqrt(4*q*Td);
PNSize = fix(T/Tpn);
PN = sign(randn(1,PNSize));
Nd = fix(T/Td);
TT = ((0:Nd-1)*Td);

PSP = PN(1+mod(fix((0:Nd-1)*Td/Tpn),PNSize));
plot(TT,PSP);

for k = 1:Nd
S(k) = PSP(k)*cos(2*pi*fi*TT(k));
end

for n=1:100
y = A*S + randn(1,Nd);
I(n) = y*S';
end
Q = 20*log10(mean(I)/std(I))-3;
%plot(I);
JS = 10^(60/10);
Aj = A*sqrt(JS);
fii = 9e6;
Y = Aj*cos(2*pi*fii*TT)+A*S+randn(1,Nd);
S = abs(fft(Y));
S = S/max(S);
plot(TT,20*log10(S));
h = -60;
for k=1:1000
    if 20*log(S(k)) > h;
      20*log(S(k)) = 0;
    else
      20*log(S(k)) = 20*log(S(k)); 

